<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>中间件代理跨域</title>
</head>
<body>
<h1>中间件代理跨域</h1>
<p>npx http-server --port=9000</p>
<script>
  // fetch('http://localhost:8080/api/community/home-api/v1/get-tab-total?username=qq_41887214', {
  //   credentials: 'include', // 前端跨域携带cookie
  // })
  // .then(response => response.json())
  // .then(res => {
  //   console.log(res);
  // })

  var xhr = new XMLHttpRequest(); // IE8/9需用window.XDomainRequest兼容

  // 前端设置是否带cookie
  xhr.withCredentials = true;

  xhr.open('get', 'http://localhost:8080/api/community/home-api/v1/get-tab-total?username=qq_41887214', true);
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xhr.send('user=admin');

  xhr.onreadystatechange = function() {
    if (xhr.readyState === 4 && xhr.status === 200) {
      console.log(JSON.parse(xhr.responseText));
    }
  };
</script>
</body>
</html>
